import pytest
import logging
from api.ihrm_addemp_api import AddEmp
from common.DBTool_ihrm import DBTools
from common.assert_ihrm import AssertIhrm
from common.get_header import get_header
from common.read_json import read_json_data
from config import BASE_PATH, TEL


class TestAddEmp(object):
    def setup_class(self):
        self.emp = AddEmp()
        self.emp_head = get_header()
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    def teardown(self):
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    file_name = BASE_PATH + "/data/ihrm_addemp_data.json"
    emp_data = read_json_data(file_name)

    @pytest.mark.parametrize("desc,req_body,status_code,success,code,message", emp_data)
    def test_add_emp(self, desc, req_body, status_code, success, code, message):
        resp = self.emp.add_emp(self.emp_head, req_body)
        logging.info(f"“这是晚自习作业题的日志信息 , {desc}:{resp.json()}")
        # print(desc, resp.json())
        AssertIhrm.assert_ihrm(resp, status_code, success, code, message)
